from flask import Flask, jsonify
from Day09.models import db
from rediscluster import StrictRedisCluster
from Day09.cache_tool import UserProfileCache

app = Flask(__name__)
class Config(object):
    SQLALCHEMY_DATABASE_URI = 'mysql://root:mysql@127.0.0.1/toutiao'
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    SQLALCHEMY_ECHO = True

    # redis 集群
    REDIS_CLUSTER = [
        {'host': '127.0.0.1', 'port': '7000'},
        {'host': '127.0.0.1', 'port': '7001'},
        {'host': '127.0.0.1', 'port': '7002'},
    ]
app.config.from_object(Config)
app.redis_cluster = StrictRedisCluster(startup_nodes=app.config['REDIS_CLUSTER'])
db.init_app(app)

@app.route('/userinfo/<int:user_id>')
def userinfo(user_id):
    """
    获取用户信息
    :param user_id:
    :return:
    """
    cache_obj = UserProfileCache(user_id)
    user_data = cache_obj.get()
    return jsonify(user_data)
if __name__ == '__main__':
    app.run(host='192.168.226.129', debug=True)